﻿using System;

using SBPweb.RIA.Shared.Contracts.Components;

using SBPweb.PROvibe.Server.Library.Modularity;

using SBPweb.PROvibe.Shared.Library.Base;
using SBPweb.PROvibe.Shared.Library.Components;

namespace SBPweb.PROvibe.Server.Library.Services
{

    public abstract class ServiceBase : InitializableBase, IService
    {

        #region Constructor logic

        protected ServiceBase(IModule parent)
        {
            Parent = parent;
        }

        #endregion

        #region Properties

        public virtual IModule Parent
        {
            get;
            private set;
        }

        public virtual ServerModuleBase ParentModule
        {
            get
            {
                return Parent as ServerModuleBase;
            }
        }

        public abstract Type Type
        {
            get;
        }

        public abstract string Name
        {
            get;
        }

        #endregion

        #region Methods

        public int CompareTo(object obj)
        {
            return CompareTo(obj as INameable);
        }

        public int CompareTo(INameable other)
        {
            if (other == null)
            {
                return 0;
            }
            return this.Name.CompareTo(other.Name);
        }
        
        #endregion
        
    }

    public abstract class ServiceBase<T> : ServiceBase
    {

        #region Constructor logic

        protected ServiceBase(IModule parent)
            : base(parent)
        {
        }

        #endregion

        #region Properties

        public override Type Type
        {
            get
            {
                return typeof(T);
            }
        }

        #endregion

    }

}